package com.ddpt.permission.dubbo;

import cn.hutool.json.JSONUtil;
import com.lh.center.common.constant.RedisPrefix;
import com.lh.center.merchant.api.entity.Merchant;
import com.lh.center.merchant.api.entity.MerchantIns;
import com.lh.center.permission.api.dubbo.DubboOpenApiService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.data.redis.core.StringRedisTemplate;

import javax.annotation.Resource;

@DubboService
public class DubboOpenApiServiceImpl implements DubboOpenApiService {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public Merchant getByAccessTokenToken(String accessToken) {
        String val = stringRedisTemplate.opsForValue().get(RedisPrefix.OPEN_ACCESS_TOKEN + accessToken);
        if(StringUtils.isBlank(val)){
            return null;
        }
        return JSONUtil.toBean(val,Merchant.class);
    }

    @Override
    public MerchantIns getMerchantInsByAccessToken(String accessToken) {
        String val = stringRedisTemplate.opsForValue().get(RedisPrefix.OPEN_ACCESS_TOKEN_INS + accessToken);
        if(StringUtils.isBlank(val)){
            return null;
        }
        return JSONUtil.toBean(val,MerchantIns.class);
    }
}
